<?php

namespace App\Admin\Extensions\Tools\Pmtag;

use Encore\Admin\Admin;
use Encore\Admin\Grid\Tools\AbstractTool;
use Illuminate\Support\Facades\Request;

class PmtagStatus extends AbstractTool
{
    protected function script()
    {
        $published = Request::get('published') ? Request::get('published') : 'all';
        $url = Request::fullUrlWithQuery(['status' => '_status_', 'published' => $published]);

        return <<<EOT

$('input:radio.pmtag-status').change(function () {

    var url = "$url".replace('_status_', $(this).val());

    $.pjax({container:'#pjax-container', url: url });

});

EOT;
    }

    public function render()
    {
        Admin::script($this->script());
        $options = [
            'all'   => '所有',
            'on'     => '上线',
            'off'     => '下线',
        ];
        return view('admin.tools.pmtag.pmtag-status', compact('options'));
    }
}